# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: John Regan <john@jrjrtech.com>
pkgname=ejabberd
pkgver=17.09
pkgrel=5
pkgdesc="An erlang jabber server"
url="https://www.ejabberd.im/"
arch="all !mips !mips64" # blocked by erlang
license="GPL-2.0-or-later"
_erl_deps="erlang-asn1 erlang-crypto erlang-eldap erlang-mnesia
	erlang-public-key erlang-sasl erlang-ssl erlang-syntax-tools
	"
_erl_make_deps="erlang-eunit erlang-parsetools"
depends="erlang util-linux yaml $_erl_deps"
depends_dev="erlang-dev expat-dev openssl-dev zlib-dev heimdal-dev yaml-dev git"
makedepends="$depends_dev $_erl_make_deps automake autoconf gd-dev
	libjpeg-turbo-dev libpng-dev libwebp-dev"
pkgusers="ejabberd"
pkggroups="ejabberd"
install="$pkgname.pre-install"
options="!check" # test suite requires all kinds of services running
subpackages="$pkgname-dev $pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/processone/$pkgname/archive/$pkgver.tar.gz
	https://github.com/processone/fast_tls/archive/1.0.7.tar.gz
	ejabberd.initd
	ejabberd.logrotate
	ejabberd.confd
	makefile.patch
	"

prepare() {
	mkdir deps
	mv "$srcdir"/fast_tls-1.0.7 "$builddir"/deps/fast_tls
	default_prepare
	./autogen.sh
}

build() {
	./configure --prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -d ${pkgdir}/var/spool/$pkgname
	install -d ${pkgdir}/var/lib/$pkgname
	install -D -m0644 "$srcdir"/$pkgname.logrotate \
		${pkgdir}/etc/logrotate.d/$pkgname
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	chown -R ejabberd.ejabberd "$pkgdir"/var/log/ejabberd
	chown -R ejabberd.ejabberd "$pkgdir"/var/spool/ejabberd
	chown -R ejabberd.ejabberd "$pkgdir"/var/lib/ejabberd
	chgrp ejabberd "$pkgdir"/etc/ejabberd/ejabberd.yml \
		"$pkgdir"/etc/ejabberd/ejabberdctl.cfg "$pkgdir"/etc/ejabberd
}

sha512sums="3eb253642d6688bbe93d0a1234ac29725ed02ed929a1b87a8424e9d01b2200eb174192cd164ba2c31fb8082e92b2886e4068effa504f66025809685867ba90f0  ejabberd-17.09.tar.gz
46a3ebab09ec5e18b086c8c3e2a87a5d6a35e406e8988c48979d94c3e303d5f9a8bcdb1e8ce74266ba8c59fbb4a4310e445f5ad65f072d28a7b44a0bdec50b62  1.0.7.tar.gz
e2310e1b5b471e5c27ce2ec5d5fc6549656f9f49ba1d65a515ebc3af6d3237a461894c6c4c55c8c6eb1b9be0b01573057591ead51eb9014f5cf1258d387c9fc8  ejabberd.initd
47fd2cfd9177c4e978a9799a153ba74392a9891822221af8194686a40f6bf01f38644833e1e1f5416c6357e0bfb7ca3dae96f55a4fcd7cd629ec798d85a72807  ejabberd.logrotate
96a571c0ab2be366e931bda423a61ef920cbaba2107e61ddbc501472ce3efe2804418cc6579c99310b902a9a99aaecb9284cf2420c071dbca2f670efb4034135  ejabberd.confd
36eacec7780ed95ffc310db30e34f9d5ba8ead65f8fc44fb06c7d825f7252effad83e07c4a010e65b80a63f4a1d985290e8a489906a8c225c306f5b5b642ce36  makefile.patch"
